package com.project.internship.controller.info;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.internship.entity.Student;
import com.project.internship.entity.Teacher;
import com.project.internship.entity.Teacher;
import com.project.internship.entity.resp.RespBean;
import com.project.internship.entity.resp.RespPageBean;
import com.project.internship.service.TeacherService;
import com.project.internship.vo.TeacherDeptVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学院端教师信息
 */
@RestController
@RequestMapping("/information/teacher")
public class InfoTeacherController {

    @Autowired
    TeacherService teacherService;

    @GetMapping("/")
    public RespPageBean getAllTeachers(@RequestParam(defaultValue = "1") Integer current,
                                       @RequestParam(defaultValue = "10") Integer size,
                                       String keyword){
        Page<Teacher> page = new Page<>(current,size);

        Long total = teacherService.getAllTeachers(page,keyword).getTotal();
        List<Teacher> data =  teacherService.getAllTeachers(page,keyword).getRecords();

        return new RespPageBean(total,data);
    }

    /**
     * 添加教师
     * @param teacher
     * @return
     */
    @PostMapping("/")
    public RespBean addTeacher(@RequestBody Teacher teacher){
        if(teacherService.addTeacher(teacher) == 1){
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    /**
     * 更新教师信息
     * @param teacher
     * @return
     */
    @PutMapping("/")
    public RespBean updateTeacher(@RequestBody Teacher teacher){
        if(teacherService.updateTeacher(teacher) == 1){
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
     * 删除一条教师信息
     * @param id 教师表中的主键id
     * @return
     */
    @DeleteMapping("/{id}")
    public RespBean deleteTeacher(@PathVariable("id") Long id){
        if(teacherService.deleteTeacher(id) == 1){
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    /**
     * 批量删除教师信息
     * @param ids
     * @return
     */
    @DeleteMapping("/")
    public RespBean deleteTeachers(@RequestBody Long[] ids){
        if(teacherService.deleteTeachers(ids) == ids.length){
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

}
